<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class mgamescores extends MY_Model {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );
    public $mytable = "game_scores";
    public $primaryKey = "gscore_id";
    public $resCode = "GAME_SCORES";

    function __construct() {
        parent::__construct();
    }

    function field() {
		$fieldData = array();
		$fieldData['game_id'] = 0;
		$fieldData['use_id'] = 0;
		$fieldData['gscore_scores'] = 0;
		$fieldData['gscore_time_create'] = 0;
		$fieldData['gscore_ip'] = '';
		$fieldData['gscore_use_scoreplus'] = 0;
		return $fieldData;
    }
	
	function get_scores_by_user_time($user_id = 0, $time_start = 0, $time_end = 0, $type_select = '') {
		switch($type_select){
			case 'sum':
				$this->db->select_sum('gscore_scores','total');
			break;
		}
		$this->db->where("gscore_time_create >=",$time_start);
		$this->db->where("gscore_time_create <=",$time_end);
		return $this->get($user_id,'use_id');
	}
	
	function save_score($game_id = 0, $user_id = 0, $score = 0)
	{
		if($user_id ==0) $user_id = $this->muser->use_id;
		if($game_id == 0 || $user_id == 0 || $score == 0)
			return false;
		$arr_insert= array();
		$arr_insert['game_id'] = $game_id;
		$arr_insert['use_id'] = $user_id;
		$arr_insert['gscore_scores'] = $score;
		$arr_insert['gscore_time_create'] = time();
		$arr_insert['gscore_time_update'] = time();
		$arr_insert['gscore_ip'] =  $this->input->ip_address();
		$this->insert($arr_insert);
		return true;
	}
}

?>